package com.huxiu.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.huxiu.R;
import com.huxiu.UpdateActivity;
import com.umeng.update.UmengUpdateAgent;
import com.umeng.update.UmengUpdateListener;
import com.umeng.update.UpdateResponse;
import com.umeng.update.UpdateStatus;

/**
 * Created by caoyuanjing on 15/12/28.
 */
public class UmengUpdate implements UmengUpdateListener {
    private Context mContext;
    private TextView mTextView;
    private static boolean mboolean;
    public UmengUpdate(Context mContext, TextView mTextView,boolean mboolean) {
        this.mContext = mContext;
        this.mTextView = mTextView;
        this.mboolean=mboolean;
    }
    public UmengUpdate(Context mContext,boolean mboolean)  {
        this.mContext = mContext;
        this.mboolean=mboolean;
    }

    public void setDialogopen(boolean mboolean){
        this.mboolean=mboolean;
    }

    @Override
    public void onUpdateReturned(int updateStatus, UpdateResponse updateInfo) {
        switch (updateStatus) {
            case UpdateStatus.Yes: // has update
                if(mTextView!=null){
                    mTextView.setVisibility(View.VISIBLE);
                    mTextView.setText("最新版本" + updateInfo.version);
                }

                if(mboolean){
                    Intent intent =new Intent(mContext,UpdateActivity.class);
                    intent.putExtra(Constants.UMENG_UPDATE_INTENT_KEY, updateInfo);
                    mContext.startActivity(intent);
//                    (Activity)mContext.overridePendingTransition(R.anim.activity_open, 0);
                }
//                UmengUpdateAgent.showUpdateDialog(mContext, updateInfo);
                break;
            case UpdateStatus.No: // has no update
                if(mTextView!=null){
                    mTextView.setVisibility(View.VISIBLE);
                    mTextView.setText("已是最新版本");
                }
//                        Toast.makeText(SettingActivity.this, "没有更新", Toast.LENGTH_SHORT).show();
                break;
            case UpdateStatus.NoneWifi: // none wifi
//                        Toast.makeText(SettingActivity.this, "没有wifi连接， 只在wifi下更新", Toast.LENGTH_SHORT).show();
                break;
            case UpdateStatus.Timeout: // time out
//                        Toast.makeText(SettingActivity.this, "超时", Toast.LENGTH_SHORT).show();
                break;
        }
    }


    public static boolean isUpate() {

        return false;
    }


}
